/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import java.util.List;
import models.FAQ;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Aster
 */
public class FAQDao {
    private final Session session;
    
    public FAQDao(Session session) {
        this.session = session;
    }
    
      public List<FAQ> findAll() {
        Transaction tx = session.beginTransaction();
        List<FAQ> list = session.createQuery("from FAQ").list();
        tx.commit();
        return list;
    }
    
    public void save(FAQ faq) {
        Transaction tx = session.beginTransaction();
        session.save(faq);
        tx.commit();
    }

    public void update(FAQ faq) {
        Transaction tx = session.beginTransaction();
        session.update(faq);
        tx.commit();
    }

    public FAQ get(long id) {
        return (FAQ) session.get(FAQ.class, id);
    }
        
    public void delete(FAQ faq) {
        Transaction tx = session.beginTransaction();
        session.delete(faq);
        tx.commit();
    }
}
